package com.zbkj.admin.controller.platform;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.ZfbDeviceBatchesItemsSearchRequest;
import com.zbkj.common.request.ZfbDeviceBatchesSaveRequest;
import com.zbkj.common.request.ZfbDeviceBatchesSearchRequest;
import com.zbkj.common.response.ZfbDeviceBatchesItemsPageDataResponse;
import com.zbkj.common.response.ZfbDeviceBatchesPageDataResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.service.service.ZfbDeviceBatchesItemsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.zbkj.service.service.ZfbDeviceBatchesService;


/**
 * 蓝牙接收器管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/device/batches")
@Api(tags = "蓝牙接收器管理") //配合swagger使用

public class PlatformZfbDeviceBatchesController {

    @Autowired
    private ZfbDeviceBatchesService zfbDeviceBatchesService;

    @Autowired
    private ZfbDeviceBatchesItemsService zfbDeviceBatchesItemsService;

    /**
     * 分页显示设备批次表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-06-11
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<ZfbDeviceBatchesPageDataResponse>> getList(@Validated @ModelAttribute ZfbDeviceBatchesSearchRequest request,
                                                                   @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<ZfbDeviceBatchesPageDataResponse> zfbDeviceBatchesCommonPage = CommonPage.restPage(zfbDeviceBatchesService.getList(request, pageParamRequest));
        return CommonResult.success(zfbDeviceBatchesCommonPage);
    }

    /**
     * 新增设备批次表
     * @param zfbDeviceBatchesSaveRequest 新增参数
     * @author dazongzi
     * @since 2025-06-11
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated ZfbDeviceBatchesSaveRequest zfbDeviceBatchesSaveRequest) {
        if(zfbDeviceBatchesService.create(zfbDeviceBatchesSaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 删除设备批次表
     * @param id Integer
     * @author dazongzi
     * @since 2025-06-11
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
        if (zfbDeviceBatchesService.removeByIdAdmin(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
      * 分页显示设备明细表
      *
      * @param deviceId          设备
      * @param request          搜索条件
      * @param pageParamRequest 分页参数
      * @author dazongzi
      * @since 2025-06-11
      */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "明细列表") //配合swagger使用
    @RequestMapping(value = "/{deviceId}/items/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<ZfbDeviceBatchesItemsPageDataResponse>> getList(@PathVariable(value = "deviceId") Integer deviceId, @Validated ZfbDeviceBatchesItemsSearchRequest request,
                                                                                   @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<ZfbDeviceBatchesItemsPageDataResponse> zfbDeviceBatchesItemsCommonPage =
                CommonPage.restPage(zfbDeviceBatchesItemsService.getList(request, pageParamRequest, deviceId));
        return CommonResult.success(zfbDeviceBatchesItemsCommonPage);
    }

}



